let href = location.href;
function getUrldata(url) {
    url = decodeURI(url)
    // console.log(queryString)
    let reg = /^[^\s]+\?([^&\s\d]+=[^\s]+)*/
    let match = reg.exec(url)[1];
    if (!match) {//表示没匹配到
        console.warn("没有匹配到相应的query参数")
        return null
    }
    var queryArr = match.split("&");
    // console.log(queryArr);
    var queryobj = {};
    queryArr.forEach(item => {
        var itemarr = item.split("=")
        queryobj[itemarr[0]] = itemarr[1];
    })
    return queryobj;
}
let qr = getUrldata(href);

var htmlnav = `
<a href="./index.html">首页</a>&nbsp;>&nbsp;<a href="./brandTitle.html">全部分类</a>&nbsp;>&nbsp;<a href="#">${qr.title}</a>

`;

$("nav").html(htmlnav);
changecontent()


function changecontent() {
    $.ajax({
        url: "http://chst.vip:1234/api/getbrandproductlist",
        type: "Get",
        data: {
            brandtitleid: qr.brandtitleid

        },
        success(sus) {
            console.log(sus);
            var htmlproduct = "";
            //  console.log(sus.result);
            sus.result.forEach(item => {
                htmlproduct += `
                 <div productId=${item.productId}  class="productItem">
                    <div class="left">
                        ${item.productImg}
                    </div>
                    <div class="right">
                        <h3>${item.productName}</h3>
                        <b>${item.productPrice}</b>
                        <p><span>${item.productQuote}</span><span>${item.productCom}</span></p>
                    </div>
 
                 </div>
                 
                 `

            })
            $("main .product").html(htmlproduct);

        }
    }).then(res => {
        $("main .product").on("click", ".productItem", function () {

            let title = qr.title;
            let productid = $(this).attr("productid");

            location.href = `./productlist.html?productid=${productid}&title=${title}`
        })
    })
}